<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <script type="text/javascript" src="../static/lib/html5shiv.js"></script>
  <script type="text/javascript" src="../static/lib/respond.min.js"></script>
  <script type="text/javascript" src="../static/lib/jquery/1.9.1/jquery.min.js"></script>
  <link rel="stylesheet" href="../static/h-ui/css/H-ui.css" />
  <link rel="stylesheet" href="../static/css/company.css" />
  <meta charset="UTF-8">
  <title>Edit Company Information</title>
</head>
<body>
<article class="page-container">
  <div class="panel panel-default">

    <div class="panel-header">Edit Company Information</div>
    <div class="panel-body">
      <form action="" method="post" class="form form-horizontal" id="form-company-add">
        <div class="row cl">
          <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>公司名称（中文）：</label>
          <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="" placeholder="" id="nameCN" name="nameCN">
          </div>

        </div>
        <div class="row cl">
          <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>公司名称（英文）：</label>
          <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="" placeholder="" id="nameEN" name="nameEN">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>品牌商认证类型：</label>
          <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="" placeholder="" id="GMCtype" name="GMCtype">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>证书地址：</label>
          <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="" placeholder="url:" id="comUrl" name="comUrl">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-xs-4 col-sm-3">公司简介：</label>
          <div class="formControls col-xs-8 col-sm-9">
            <textarea id="info" name="info" cols="" rows="" class="textarea" placeholder="请输入"></textarea>
            <p class="textarea-numberbar"><em class="textarea-length">0</em>/<am>100</am></p>
          </div>
        </div>
        <div class="row cl">
          <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <button class="btn btn-primary-outline radius" id="btnback">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>
            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
          </div>
        </div>
      </form>
    </div>
  </div>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">

  window.onload = load;
  var com = {}

  function getoldcom(){
    var url = decodeURI(location.search); 			//获取url中"?"符后的字串 ('?aaa=123&bbb=456')
    console.log(url);
    var theRequest = {};
    if ( url.indexOf( "?" ) !== -1 ) {
      var str = url.substr( 1 ); 		//substr()方法返回从参数值开始到结束的字符串；
      var strs = str.split( "&" );
      for ( var i = 0; i < strs.length; i++ ) {
        theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ]);
      }
      console.log( theRequest );		//此时的theRequest就是我们需要的参数；
      var urlValue;
      //这一步是我把获取的参数的值取出来，并附给变量，
      $.each(theRequest,function(index,val){
        urlValue = val;
      });
    }
    console.log(theRequest.nameCn);
    return theRequest;
  }

  function load(){
    var theRequest = getoldcom();
    com = theRequest;
    $("#nameCN").attr("value",theRequest.nameCn);
    $("#nameEN").attr("value",theRequest.nameEn);
    $("#GMCtype").attr("value",theRequest.rType);
    $("#comUrl").attr("value",theRequest.rUrl);
    $("#info").val(theRequest.cinfo);
  }

  function getComInfo(){
    var nameCn = $("#nameCN").val();
    var nameEn = $("#nameEN").val();
    var GMCtype = $("#GMCtype").val();
    var comURL = $("#comUrl").val();
    var info = document.getElementsByName("info")[0].value;
    var comInfo = {
      'companyId':com.companyId,
      'nameCn':nameCn,
      'nameEn':nameEn,
      'info':info,
      'rType':GMCtype,
      'rUrl':comURL
    }
    console.log(comInfo)
    return comInfo;
  }

  $(function() {
    $("#btnback").click(function () {
      window.location.href = "/mvo/getmvoinfo";
    });


    $('.skin-minimal input').iCheck({
      checkboxClass: 'icheckbox-blue',
      radioClass: 'iradio-blue',
      increaseArea: '20%'
    });

    $("#form-company-add").validate({
      rules: {
        nameCn:{
          required:true,
          minlength:2,
          maxlength:30
        },nameEn:{
          required:true,
          minlength:2,
          maxlength:100
        },GMCtype:{
          required:true,
          minlength:2,
          maxlength:30
        },comUrl:{
          required:true,
          minlength:2,
          maxlength:100
        },info:{
          maxlength:100
        }

      },
      onkeyup: false,
      focusCleanup: true,
      success: "valid",
      submitHandler: function (form) {
        var comInfo = getComInfo();
        var url = "/mvo/updatecom";
        $.ajax({
          type: 'POST',
          url: url,
          data: JSON.stringify(comInfo),
          contentType: "application/json",
          dataType: 'json',
          success: function () {
            console.log("1111")
            window.location.href="/mvo/getmvoinfo";
          }
        });
      }
    });
  })

</script>
</body>
</html>

